package com.example.content_server.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * @author: snjgm
 * data: 2022/7/18
 * description:
 */
public class UserDbHelper extends SQLiteOpenHelper {
    private static final String DB_NAME = "info";
    private static final int DB_VERSION = 1;
    public static final String TABLE_NAME = "user_info";
    private static UserDbHelper mHelper = null;

    private UserDbHelper(Context context) {
        super(context, DB_NAME, null, DB_VERSION);
        
    }

    //利用单例模式获取数据库帮助的唯一实例
    public static UserDbHelper getInstance(Context context){
        if (mHelper == null){
            mHelper = new UserDbHelper(context);
        }
        return mHelper;

    }

    //创建数据库，执行建表语句
    @Override
    public void onCreate(SQLiteDatabase db) {
        String sql = "CREATE TABLE IF NOT EXISTS " + TABLE_NAME + " ("
                + "_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "
                + "name VARCHAR NOT NULL," + "age INTEGER NOT NULL,"
                + "married INTEGER NOT NULL," + "update_time VARCHAR NOT NULL"
                //演示数据库升级时要先把下面这行注释
//                + ",phone VARCHAR" + ",password VARCHAR"
                + ");";
        //执行完整的SQL语句
        db.execSQL(sql);
    }
    //
    @Override
    public void onUpgrade(SQLiteDatabase db, int i, int i1) {}

}
